package ch.netcetera.planningpoker.client.ui.widget.userlist;

import ch.netcetera.planningpoker.client.model.resources.Resources;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.HasClickHandlers;
import com.google.gwt.event.dom.client.MouseOutEvent;
import com.google.gwt.event.dom.client.MouseOutHandler;
import com.google.gwt.event.dom.client.MouseOverEvent;
import com.google.gwt.event.dom.client.MouseOverHandler;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Widget;

public class UserView extends Composite {

    private static UserViewUiBinder uiBinder = GWT
            .create(UserViewUiBinder.class);

    interface UserViewUiBinder extends UiBinder<Widget, UserView> {
    }
    
    @UiField
    Label userName;
    
    @UiField
    Image closer;

    private Resources resources;

    public UserView() {
        initWidget(uiBinder.createAndBindUi(this));
        resources = GWT.create(Resources.class);
        closer.addMouseOverHandler(new MouseOverHandler() {
            
            @Override
            public void onMouseOver(MouseOverEvent event) {
                closer.setResource(resources.closerHover());
                
            }
        });
        closer.addMouseOutHandler(new MouseOutHandler() {
            
            @Override
            public void onMouseOut(MouseOutEvent event) {
                closer.setResource(resources.closer());
            }
        });
    }
    
    public void setUserName(String userNameText) {
        userName.setText(userNameText);
        closer.setTitle("Delete " + userNameText + "?");
    }
    
    public HasClickHandlers getCloser() {
        return closer;
    }

}
